package cn.itcast.bos.service.system.impl;

import cn.itcast.bos.dao.system.PermissionRepositor;
import cn.itcast.bos.domain.system.Permission;
import cn.itcast.bos.domain.system.User;
import cn.itcast.bos.service.system.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class PermissionServiceImpl implements PermissionService {

    @Autowired
    private PermissionRepositor permissionRepositor;

    @Override
    public List<Permission> findByUser(User user) {
//        List<Permission> list = permissionRepositor.findPermissionByUser(user.getId());
        if (user.getUsername().equalsIgnoreCase("admin")){
            return permissionRepositor.findAll();
        }else {
            return permissionRepositor.findPermissionByUser(user.getId());
        }
    }

    @Override
    public List<Permission> findAll() {
        List<Permission> all = permissionRepositor.findAll();
        return all;
    }

    @Override
    public void save(Permission model) {
        permissionRepositor.save(model);
    }

    @Override
    public Permission findOne(int i) {
        Permission one = permissionRepositor.findOne(i);
        return one;
    }
}
